<template lang="html">
  <el-dialog  :close-on-click-modal="closeonclickmodal"  width="480px" :title="getdialogTitle()" @open="listenopen()" @close="close" :visible="dialogshow">
    <el-form  :model="dialoginfo" ref="dialoginfo" label-position="left" >
          <el-form-item  :rules="[{ required: true, message: '不能为空'}]"
                          prop="name" label="角色名称" :label-width="formLabelWidth">
            <el-input  v-model="dialoginfo.name" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="desc" label="角色备注" :label-width="formLabelWidth">
            <el-input   v-model="dialoginfo.desc" auto-complete="off" clearable></el-input>
          </el-form-item>
          <!--<el-form-item label="是否公开" :label-width="formLabelWidth">-->
            <!--<el-switch-->
              <!--v-model="dialoginfo.open"-->
              <!--active-color="#13ce66"-->
              <!--inactive-color="#ff4949">-->
            <!--</el-switch>-->
          <!--</el-form-item>-->
      <el-row>
        <el-form-item style="text-align: right">
          <el-button size="mini" @click="dialogshow = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="toaddPerm('dialoginfo')">确 定</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>
  export default {
    inject:["reload"],
    data() {
      return {
        isajax:false,
        closeonclickmodal:false,
        formLabelWidth: '80px'
      }
    },
    props:['dialogshow','dialoginfo','isadd'],
    methods:{

      getdialogTitle(){
        return this.isadd==true?"新增系统角色":"修改系统角色";
      },
      listenopen(){
        if(this.isadd&&this.$refs['dialoginfo']!=null){
          this.$refs['dialoginfo'].resetFields();
        }
        // console.log(this.isadd);
        // console.log(this.dialogshow);
      },
      close(){
        this.$emit('changedialogshow')
      },
      toaddPerm(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.isajax=true;
            this.proAPI.postJson(this.isadd?this.proAPI.URLS.addSysRole:this.proAPI.URLS.modifyRole,this.dialoginfo).then((res) =>{
                if(res!=null){
                  // console.log(res);
                  this.$message.success({
                    "message":res.message
                  })
                  setTimeout(()=>{
                    this.reload();

                  },1000)
                }else{
                  // console.log(1233333);
                }
                this.isajax=false;
              });
          }else{
              return false;
          }
        });
      }
    },
    updated(){
      // console.log(333);
    },
    mounted(){
      // console.log("开始创建！！！！！！！！！！！！！！！！！");
    }
  };
</script>
<style lang="css">
</style>
